
#include "shipobject.h"

int ShipObject::nextId = 0;

bool ShipObject::testHit(int hitRow, int hitCol) const {
    if (orientationPortrait) {
        if (col == hitCol && row <= hitRow && hitRow < row + hp) {
            return true;
        }
    } else if (row == hitRow && col <= hitCol && hitCol < col + hp) {
        return true;
    }
    return false;
}

bool ShipObject::overlaps(const ShipObject &s) const {
    for (size_t i = 0; i < hp; ++i) {
        if (orientationPortrait) {
            if (s.testHit(row + i, col)) {
                return true;
            }
        } else {
            if (s.testHit(row, col + i)) {
                return true;
            }
        }
    }
    return false;
}

